package com.timk.goserver.server.util;

import java.util.LinkedList;
import java.util.List;

/**
 * Blocking queue
 * @author TKington
 *
 */
public class BlockingQueue {
	private final List queue = new LinkedList();
	
	/**
	 * Puts an object in the queue, notifies the consumer
	 * @param o the object
	 */
	public synchronized void put(Object o) { // NOPMD - Use block-level synchronization
		queue.add(o);
		notifyAll();
	}
	
	/**
	 * Gets the next object in the queue.  Blocks if no objects are present
	 * @return the object
	 * @throws InterruptedException
	 */
	public synchronized Object get() // NOPMD - Use block-level synchronization
			throws InterruptedException {
		while(queue.isEmpty()) {
			wait();
		}
		
		return queue.remove(0);
	}
}
